<?php

/**
 * AuditoriaEntidad form.
 *
 * @package    sistema_estadisticas
 * @subpackage form
 * @author     Your name here
 * @version    SVN: $Id: sfDoctrineFormTemplate.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
 */
class AuditoriaEntidadForm extends BaseAuditoriaEntidadForm
{
	public function configure()
	{
		if ($this->getObject()->isNew())
		{
			$this->widgetSchema['entidad'] = new sfWidgetFormChoice(array('choices' => Auditable::getAuditableModels()));
			$this->validatorSchema->setPostValidator(
				new sfValidatorDoctrineUnique(array('model' => 'AuditoriaEntidad', 'column' => 'entidad'))
			);
			$this->validatorSchema->getPostValidator()
				->setMessage('invalid', 'La auditoría a esta entidad ya existe.');
		}
		else
			$this->widgetSchema['entidad'] = new WidgetFormHiddenInfo(array('model' => 'AuditoriaEntidad', 'column' => 'entidad', 'query_column' => 'entidad'));

		$this->validatorSchema['f_actualizacion'] = new sfValidatorPass();
		$this->validatorSchema['u_actualizacion'] = new sfValidatorPass();
	}

	public function doSave($con = null)
	{
		if (null === $con)
		{
			$con = $this->getConnection();
		}

		$this->updateObject();
		$this->getObject()->setFActualizacion(date('Y-m-d H:i:s', time()));
		$this->getObject()->setUActualizacion(sfContext::getInstance()->getUser()->getUsername());

		$this->getObject()->save($con);
	}

}
